<template>
  <div class="wrap">
    <el-form
      label-position="right"
      ref="form"
      :model="form"
      label-width="120px"
    >
      <el-form-item label="优势:">
        <div class="tagList" :key="tag.id" v-for="tag in dynamicTags">
          <el-tag
            :closable="tag.id == 1 ? false : true"
            :disable-transitions="false"
            @close="handleClose(tag.id)"
          >
            {{ tag.name }}
          </el-tag>
        </div>
        <el-button class="button-new-tag" size="small" @click="addTag"
          >+ 优势</el-button
        >
      </el-form-item>
      <div class="tagCont" :key="tag.id" v-for="tag in dynamicTags">
        <el-form-item :label="tag.name + '标题:'">
          <el-input
            style="width: 20%"
            type="input"
            v-model="tag.tit"
          ></el-input>
        </el-form-item>
        <el-form-item :label="tag.name + '内容:'">
          <el-input type="textarea" v-model="tag.desc"></el-input>
        </el-form-item>
        <el-form-item :label="tag.name + '宣传图:'">
          <el-upload
            action=""
            :list-type="tag.listType"
            :auto-upload="false"
            :limit="1"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <i class="el-icon-plus"></i>
            <div slot="file">
              <imgtag
                v-if="tag.img"
                class="el-upload-list__item-thumbnail"
                :src="tag.img"
                alt=""
              />
            </div>
          </el-upload>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
export default {
  props: [{}],
  data() {
    return {
      form: {
        dynamicTags: [
          {
            id: 1,
            name: "优势1",
          },
        ],
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
    };
  },
  methods: {
    handleClose(tag) {
      this.dynamicTags.forEach((item, index) => {
        if (item.id == tag) {
          this.dynamicTags.splice(index, 1);
        }
      });
    },
    addTag() {
      var len = this.dynamicTags.length + 1;
      this.dynamicTags.push({
        id: len,
        name: "优势" + len,
      });
      // console.log(this.dynamicTags)
    },
    handleAvatarSuccess() {},
    beforeAvatarUpload() {},
    handleInputConfirm() {
      const inputValue = this.inputValue;
      if (inputValue) {
        this.dynamicTags.push(inputValue);
      }
      this.inputVisible = false;
      this.inputValue = "";
    },
    onSubmit() {
      console.log("submit!");
    },
  },
};
</script>
<style lang="scss" scoped>
.wrap {
  width: 100%;
  height: 100%;
  background-color: #fff;
  margin-bottom: 1.3%;
  padding: 24px;
  padding-bottom: 7px;
  margin-right: 15px;
  border: 1px solid rgba(229, 229, 229);
}
.tagList {
  float: left;
  margin: 0 10px;
}
.tagCont {
  margin-top: 20px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
